<template>
    <div id="ds19">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>司机管理</BreadcrumbItem>
            <BreadcrumbItem>车辆认证</BreadcrumbItem>
        </Breadcrumb>
        <div style="padding-right: 20px">
            <Input v-model="selectMobile" placeholder="查询手机号码" style="width: 150px"/>
            &nbsp;
            <Button type="info" @click="search()">查询</Button>
            <Button type="info" @click="handleDownload()" style="float: right">下载报表</Button>
        </div>

        <div style="margin-top: 10px">
            <Table :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
                   v-if="data&&data.length>0" @on-row-dblclick="rowData"></Table>

            <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
                  style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator
                  v-if="data&&data.length>0"/>
            <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
                总计 {{pageTotal}} 条数据
            </div>

        </div>
        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>

        <Modal v-model="modeBool" fullscreen>
            <div style="text-align:left;font-size: 16px">
                <div style="margin: 3px">手机号码:&nbsp;<span>{{modeData.mobile}}</span></div>
                <div style="margin: 3px">角色类型:&nbsp;<span>{{modeData.type1}}</span></div>
                <div style="margin: 3px">用户等级:&nbsp;<span>{{modeData.currentLevel}}</span></div>
                <div style="margin: 3px">车型:&nbsp;<span>{{modeData.typeName}}</span></div>
                <div style="margin: 3px">是否认证:&nbsp;<span>{{modeData.validstatus1}}</span></div>
                <div style="margin: 3px">车牌号码:&nbsp;<span>{{modeData.number}}</span></div>
                <div style="margin: 3px">车辆品牌:&nbsp;<span>{{modeData.brandName}}</span></div>
                <div style="margin: 3px">车架号:&nbsp;<span>{{modeData.vinNumber}}</span></div>
                <div style="margin: 3px">上牌时间:&nbsp;<span>{{modeData.registeDate1}}</span></div>
                <div style="margin: 3px">马力:&nbsp;<span>{{modeData.horsepower}}</span></div>
                <div style="margin: 3px">年检时间:&nbsp;<span>{{modeData.yearCheckTime1}}</span></div>

                <div style="margin: 3px">行驶证照片:</div>
                <div style="margin: 3px"><img :src="modeData.runCardPhoto1" v-if="modeData.runCardPhoto1" alt=""
                                              style="margin: 5px" width="420px">
                    <img :src="modeData.runCardPhoto2" alt="" v-if="modeData.runCardPhoto2" style="margin: 5px"
                         width="420px">
                </div>

                <div style="margin: 3px">车辆图片:</div>
                <div style="margin: 3px">

                    <li v-for="img in modeData.image1" style="list-style: none">
                        <img :src="img" style="margin: 5px"
                             width="420px">
                    </li>
                </div>


            </div>
            <div slot="footer">
                <Button type="info" @click="modeBool=false">关闭</Button>
            </div>
        </Modal>

    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                modeData: {},
                modeBool: false,
                selectMobile: "",
                loading: false,
                pageTotal: 0,
                curPage: 0,
                columns: [
                    {
                        title: '发布时间',
                        key: 'createTime1',
                        width: 155
                    },
                    {
                        title: '手机号码',
                        key: 'mobile'
                    },
                    {
                        title: '角色',
                        key: 'type1',
                        width: 100
                    },
                    {
                        title: '用户等级',
                        key: 'currentLevel',
                        width: 100
                    },
                    {
                        title: '是否认证',
                        key: 'validstatus1'
                    },
                    {
                        title: '车辆类型',
                        key: 'typeName'
                    },
                    {
                        title: '车辆品牌',
                        key: 'brandName'
                    },
                    {
                        title: '车牌号码',
                        key: 'number'
                    }
                ],
                data: []
            }
        },
        mounted(){
            this.getData();
        },
        methods: {
            rowData(data, index){
                this.modeData = data;
                this.modeBool = true;
                /* console.log(JSON.stringify(data));*/
            },
            search(){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (this.selectMobile) {
                    param.append('selectMobile', this.selectMobile + "");
                }

                this.loading = true;
                Axios.post(ipServer + "trucks/selectTrucksList", param)
                        .then(res => {

                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {
                                    res.data.data.result[i].createTime1 = sessionUtils.timestampToTime(res.data.data.result[i].createTime);
                                    res.data.data.result[i].registeDate1 = sessionUtils.timestampToTime(res.data.data.result[i].registeDate);
                                    res.data.data.result[i].yearCheckTime1 = sessionUtils.timestampToTime(res.data.data.result[i].yearCheckTime);

                                    if (res.data.data.result[i].image) {
                                        var split = res.data.data.result[i].image.split(',');

                                        for (var j = 0; j < split.length; j++) {
                                            split[j] = "http://p5thuz78a.bkt.clouddn.com/" + split[j];
                                        }
                                        res.data.data.result[i].image1 = split;
                                    }

                                    if (res.data.data.result[i].runCardPhoto) {
                                        var split = res.data.data.result[i].runCardPhoto.split(',');
                                        res.data.data.result[i].runCardPhoto1 = "http://p5thuz78a.bkt.clouddn.com/" + split[0];
                                        if (split.length > 1)
                                            res.data.data.result[i].runCardPhoto2 = "http://p5thuz78a.bkt.clouddn.com/" + split[1];
                                    }
                                    if (res.data.data.result[i].validstatus == 0) {
                                        res.data.data.result[i].validstatus1 = "未认证";
                                    }
                                    if (res.data.data.result[i].validstatus == 1) {
                                        res.data.data.result[i].validstatus1 = "待认证";
                                    }
                                    if (res.data.data.result[i].validstatus == 2) {
                                        res.data.data.result[i].validstatus1 = "认证失败";
                                    }
                                    if (res.data.data.result[i].validstatus == 3) {
                                        res.data.data.result[i].validstatus1 = "认证成功";
                                    }

                                    if (res.data.data.result[i].type == "1") {
                                        res.data.data.result[i].type1 = "司机";
                                    }
                                    if (res.data.data.result[i].type == "2") {
                                        res.data.data.result[i].type1 = "配件商";
                                    }
                                    if (res.data.data.result[i].type == "3") {
                                        res.data.data.result[i].type1 = "修理";
                                    }
                                    if (res.data.data.result[i].type == "4") {
                                        res.data.data.result[i].type1 = "补胎";
                                    }
                                    if (res.data.data.result[i].type == "5") {
                                        res.data.data.result[i].type1 = "审车";
                                    }
                                    if (res.data.data.result[i].type == "6") {
                                        res.data.data.result[i].type1 = "加油";
                                    }
                                    if (res.data.data.result[i].type == "7") {
                                        res.data.data.result[i].type1 = "吊车";
                                    }
                                }
                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                                if (this.data.length == 0)
                                    this.$Message.info("查询数据不存在!");
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$Message.info(res.data.msg);
                                this.$router.push("/login");

                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            },
            pageChange(page){
                this.getData(page);
            },
            getData(page){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (page) {
                    param.append('pageId', page + "");
                }

                if (this.selectMobile) {
                    param.append('selectMobile', this.selectMobile + "");
                }

                this.loading = true;
                Axios.post(ipServer + "trucks/selectTrucksList", param)
                        .then(res => {
                            if (res.data.code == 0) {

                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {
                                    res.data.data.result[i].createTime1 = sessionUtils.timestampToTime(res.data.data.result[i].createTime);
                                    res.data.data.result[i].registeDate1 = sessionUtils.timestampToTime(res.data.data.result[i].registeDate);
                                    res.data.data.result[i].yearCheckTime1 = sessionUtils.timestampToTime(res.data.data.result[i].yearCheckTime);

                                    if (res.data.data.result[i].image) {
                                        var split = res.data.data.result[i].image.split(',');

                                        for (var j = 0; j < split.length; j++) {
                                            split[j] = "http://p5thuz78a.bkt.clouddn.com/" + split[j];
                                        }
                                        res.data.data.result[i].image1 = split;
                                    }


                                    if (res.data.data.result[i].runCardPhoto) {
                                        var split = res.data.data.result[i].runCardPhoto.split(',');
                                        res.data.data.result[i].runCardPhoto1 = "http://p5thuz78a.bkt.clouddn.com/" + split[0];
                                        if (split.length > 1)
                                            res.data.data.result[i].runCardPhoto2 = "http://p5thuz78a.bkt.clouddn.com/" + split[1];
                                    }


                                    if (res.data.data.result[i].validstatus == 0) {
                                        res.data.data.result[i].validstatus1 = "未认证";
                                    }
                                    if (res.data.data.result[i].validstatus == 1) {
                                        res.data.data.result[i].validstatus1 = "待认证";
                                    }
                                    if (res.data.data.result[i].validstatus == 2) {
                                        res.data.data.result[i].validstatus1 = "认证失败";
                                    }
                                    if (res.data.data.result[i].validstatus == 3) {
                                        res.data.data.result[i].validstatus1 = "认证成功";
                                    }

                                    if (res.data.data.result[i].type == "1") {
                                        res.data.data.result[i].type1 = "司机";
                                    }
                                    if (res.data.data.result[i].type == "2") {
                                        res.data.data.result[i].type1 = "配件商";
                                    }
                                    if (res.data.data.result[i].type == "3") {
                                        res.data.data.result[i].type1 = "修理";
                                    }
                                    if (res.data.data.result[i].type == "4") {
                                        res.data.data.result[i].type1 = "补胎";
                                    }
                                    if (res.data.data.result[i].type == "5") {
                                        res.data.data.result[i].type1 = "审车";
                                    }
                                    if (res.data.data.result[i].type == "6") {
                                        res.data.data.result[i].type1 = "加油";
                                    }
                                    if (res.data.data.result[i].type == "7") {
                                        res.data.data.result[i].type1 = "吊车";
                                    }
                                }
                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            }, handleDownload() {
                this.loading = true;
                const list = this.data;
                require.ensure([], () => {
                    const {export_json_to_excel} = require('../../assets/js/Export2Excel') //这个地址和页面的位置相关，这个地址是Export2Excel.js相对于页面的相对位置
                    const tHeader = ["发布时间", "手机号码", "角色", "用户等级", "是否认证", "车辆类型", "车辆品牌", "车牌号码"]; //这个是表头名称 可以是iveiw表格中表头属性的title的数组
                    const filterVal = ["createTime1", "mobile", "type1", "currentLevel", "validstatus1", "typeName", "brandName", "number"]; //与表格数据配合 可以是iview表格中的key的数组
                    const data = this.formatJson(filterVal, list)
                    export_json_to_excel(tHeader, data, '车辆认证') //列表excel  这个是导出表单的名称
                    this.loading = false
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => v[j]))
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>